package Classes.GameDatas
{
	import Classes.GameUtils.GD_deal;
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.GameViews.ViewPanels.VP_NewQQVip;
	import Classes.GameViews.ViewPanels.VP_QQTQView;
	import Classes.GameViews.ViewPanels.VP_QQhzDayGift;
	import Classes.Managers.M_Communication;
	import Classes.staticinfo.Language;
	
	import UIComponents.IUseItem;
	
	import flash.display.DisplayObject;

	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：Apr 19, 2012 7:30:38 PM 
	 */ 
	public class GD_QQhz extends GameData
	{
		private static var _instance:GD_QQhz; /*静态引用*/
		public function GD_QQhz(){}
		
		public var dayGiftObj:Object;
		
		/*getter & setter*/
		public static function get instance():GD_QQhz
		{
			if (!_instance)
				_instance=new GD_QQhz;
			return _instance;
		}
		
		//发送打开新手QQ礼包命令
		public function openNewqqVip():void
		{
			M_Communication.instance.send(11003,{type:1});
//			openDayqqVip();
		}
		//打开每日QQ礼包
		public function openDayqqVip():void
		{
			var currentLv:int=GD_Player.instance.qqVipId;
			var tmpLv:int=currentLv;
			if(currentLv>100)
			{
				tmpLv=currentLv-100;
			}
			var dis:Object=dayQQGiftObj[tmpLv];
			var nex:Object=dayQQGiftObj[tmpLv+1];
			if(GD_Player.instance.isGetDayqqGift==0)
			{
				VP_QQhzDayGift.instance.contrlLqBtn(false);
			}else{
				VP_QQhzDayGift.instance.contrlLqBtn(true);
			}
			VP_QQhzDayGift.instance.openQQWin(dayQQGiftObj[tmpLv],yearobj,dayQQGiftObj[tmpLv+1]);
			
		}
		//查看特权页面
		public function seeVipTq():void
		{
			VP_QQTQView.instance.openQQtqWindon(GD_Player.instance.qqVipId,dayQQGiftObj,yearobj);
		}
		
		public function closeVipWin(flag:int):void
		{
			if(flag==1)
			{
				VP_NewQQVip.instance.close();
			}else if(flag==2)
			{
				VP_QQhzDayGift.instance.close();
			}
			VP_QQhzDayGift.instance.contrlLqBtn(false);
		}
		
		public var yearobj:Object=new Object();
		public var dayQQGiftObj:Object=new Object();
		
		
		public function setDayGifData(dayGiftArr:Array,yearStr:String):void
		{
			var yearArr:Array=this.splitResult(yearStr);
			yearobj=yearArr[0];
			
			for(var i:int=0;i<dayGiftArr.length;i++)
			{
				var tmpObj:Object=dayGiftArr[i];
				dayQQGiftObj[tmpObj.grade]=this.splitResult(tmpObj.value);
			}
		}
		
		
		//打开打开新手QQ礼包面板
		public function openQqWin(msgObj:Object):void
		{
			//打开新手
			VP_NewQQVip.instance.openNewVipWindon(splitResult(msgObj.value));
		}
		
		private function  splitResult(tmpStr:String):Array
		{
			var endArr:Array=new Array();
			
			var hkArr:Array=tmpStr.split(",");
			for(var i:int=0;i<hkArr.length;i++)
				
			{
				var obj:Object=new Object();
				var dhArr:Array=hkArr[i].toString().split("-");
				if(dhArr && dhArr.length>0)
				{
					obj.itemNum=dhArr[1];
					obj.icon=this.getSpectialIcon(dhArr[0]);
					endArr.push(obj);
				}
			}
			
			return endArr;
		}
		
		private function getSpectialIcon(id:Number=0,w:int=65,h:int=65):DisplayObject
		{
			var countPic:ViewIcon=null
			switch(id)
			{
				case 1://金币
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_JB"});
					countPic.displayViewIconName=Language.jb;
					break;
				case 3:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Act"});
					countPic.displayViewIconName=Language.act;
					break;
				case 4:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Exp"});
					countPic.displayViewIconName=Language.exp;
					break;
				case 10:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_OB"});
					countPic.displayViewIconName=Language.ob;
					break;
				default :
					var iuserItem:IUseItem=GD_deal.instance.getDataById(id);
					var vi:ViewIcon=(iuserItem.itemPic) as ViewIcon;
					countPic=ViewIcon.creat({sourceName:vi.sourceName,picName:vi.picName});
					countPic.displayViewIconName=iuserItem.itemName+"："+iuserItem.description;
					break;
			}
			countPic.iHeight=65;
			countPic.iWidth=65;
			countPic.setNumSpVisiable(false);
			return countPic;
		}
	}
}
